#include "widget.h"
#include "ui_widget.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置windowtitie
    setWindowTitle("测试代码");
    //测试透明度
    setWindowOpacity(0.95);

    //设置使能
//    button = new QPushButton(this);
//    button->setEnabled(false);
//    button->setText("移动按钮");
//    button->resize(100,100);

    label = new QLabel(this);
    label->setText("焦点测试");
    label->move(200,30);
    label->setStyleSheet("border: 3px solid red;");
    //label无法拿到焦点

    edit = new QLineEdit(this);
//    edit->setFocusPolicy(Qt::ClickFocus);
    edit->setFocusPolicy(Qt::TabFocus);
    edit->move(300,100);

    //设置光标图片和大小
    button = new QPushButton("我是按钮",this);
    button->resize(100,100);
    QPixmap pmap(":/blue.jpg");
    pmap = pmap.scaled(30,30);
    QCursor cur(pmap,0,0);
    button->setCursor(cur);

    //设置提示文本
    button->setToolTip("hello world");
    //设置文本显示时间，单位为毫秒
    button->setToolTipDuration(3000);
    //设置图片
    QIcon icon(":/blue.jpg");
    button->setIcon(icon);
    button->setStyleSheet("color: rgb(71, 204, 124);");
    button->setIconSize(QSize(100,200));

//    button->setIconSize(100,100);
    button->setShortcut(QKeySequence("r"));
    button->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_W));
    button->setAutoRepeat(true);
    connect(button,&QPushButton::clicked,this,&Widget::button_clicked);

    //单选按钮测试
}

Widget::~Widget()
{
    delete ui;
}

void Widget::button_clicked()
{
    QRect geo = button->geometry();
    button->setGeometry(geo.x() + 10,geo.y() + 10,geo.width(),geo.height());

}


void Widget::on_pushButton_text_clicked()
{
    QPixmap pmap(":/blue.jpg");
    pmap = pmap.scaled(30,30);
    QCursor cur(pmap,0,0);
    ui->pushButton_text->setCursor(cur);
}
